import 'dart:convert';

import 'package:flutter_des/flutter_des.dart';

import '../public.dart';

class RetrievalService {
  static Future getHot({int limit = 10}) async {
    String param = await FlutterDes.encryptToHex(
        "&limit=$limit&", AppConfig.cryptKey,
        iv: AppConfig.cryptIv);
    String url = AppConfig.BASE_UEL + Api.getRetrievalHot + param.toString();
    List<Retrieval> retrievals = [];
    BaseResp res = await HttpManager().request(url);
    List<dynamic> jsonObject = jsonDecode(res.data);
    retrievals = Retrieval.listFromJson(jsonObject);
    return retrievals;
  }

  static Future<List<Map<String, dynamic>>> getTypeList(
      {int page: 1, limit: 20}) async {
    List<Map<String, dynamic>> bookTypeList = [
      {"id": "全部", "name": "全部"}
    ];
    String param = await FlutterDes.encryptToHex(
        "&page=$page&"
        "&limit=$limit&",
        AppConfig.cryptKey,
        iv: AppConfig.cryptIv);
    String url = AppConfig.BASE_UEL + Api.bookTypeList + param.toString();
    BaseResp res = await HttpManager().request(url);
    Map<String, dynamic> jsonObject = jsonDecode(res.data);
    List<dynamic> _ = jsonObject['bookTypeList'];
    _.asMap().forEach((key, value) {
      bookTypeList.add({"id": value['bookType'], "name": value['bookType']});
    });
    return bookTypeList;
  }
}
